package com.lsa.cormen.ch15.samples;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;

public class TextAlignmentHelper {
    /**
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) throws Exception {
        String text = FileUtils.readFileToString(new File("doc/cormen/ch15/alignment/greedy.txt"));
        spacesStat(text);
    }
    public static void spacesStat(String text) {
        int count = 0;
        for (int i = 0; i < text.length(); i++) {
            if (Character.isWhitespace(text.charAt(i))) {
                count++;
            }
        }
        System.out.println("Whitespace count : " + count);
    }

    public static void filterAzWords(String text) {
        String[] words = text.split("\\b");
        List<String> wordsFiltered = new ArrayList<String>();
        for (String w : words) {
            w = w.trim();
            if (!w.isEmpty() && w.matches("[a-zA-Z]+")) {
                wordsFiltered.add(w);
            }
        }
        
        for (int i = 0; i < wordsFiltered.size(); i++) {
            System.out.print(wordsFiltered.get(i)+""+i+" ");
        }
    }
}